Add new Camera3D type: Oblique#89140
Open
qaptoR wants to merge 1 commit into
Open
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: godotengine/godot-proposals#501
Partial solution to this proposal: godotengine/godot-proposals#2713
This PR should not necessarily be a reason to close the proposal 2713, it is merely a straightforward implementation of oblique near plane clipping to implement a portal--or other similar--mechanic.
This PR is essentially an update to my previous PR: #64876
The main difference is that shadows were fixed.
This other PR attempts to completely solve proposal 2713 mentioned above, but apparently is having issues with shadows. Considering that its commits try to implement custom projections by adding a new camera type like with my PRs, there is a good chance the way I fixed shadows could also work there too: #84454
The solution was that along with the main Oblique camera projection a separate, normal Perspective camera projection needed to be included with the
CameraDataused in theRenderSceneCull::_render_scene()that was used explicitly for lighting and shadows.However, regarding the potential question of whether one PR should be included over the other as a solution, clearly the more general solution can see a wider range of uses. However, I believe this implementation of an Oblique Near Plane camera still has merit based on the majority use case of creating a portal mechanic, etc where oblique near clipping is necessary.
This is because the interface for the Oblique camera included in this PR has been simplified so that users are only required to provide at a minimum the transform of the plane they wish to use as the near clipping plane of the camera using
set_oblique_plane_from_transform().Additionally, because all of the required math (especially the matrix math) is happening in C++, the effect is as efficient as possible, without requiring steps to first
camera.get_projection, then doing matrix manipulation, thencamera.set_projectionall in GDScript.Alternatively, because the Oblique Near Plane matrix manipulations "... can be applied to any projection matrix, ..." (https://terathon.com/lengyel/Lengyel-Oblique.pdf, pg. 2) it's possible that all camera types (including the other proposed custom projection camera) could benefit from a general
is_oblique_near_planeboolean toggle instead of this dedicated oblique camera which only implements the algorithm for a Perspective projection.Video 1: Current state of personal portal game mechanic
https://youtu.be/A_-2nTyKVkU
Notice that the portal viewports are not blocked by the surface the portal is on (the issue with using a standard perspective camera), and that shadows and lighting appear the same when looking through the portal (as evidenced by walking through the portal where a seamless transition occurs).
Video 2: Previous video showcasing dynamically the difference oblique near plane clipping makes
https://youtu.be/PipVd6wRnMk?si=lCThReaKyO-smBaP
Note that this older video did not properly handle shadows, and the viewport texture color and environment lighting were all wrong giving it that washed out look (both fixed in Video 1).
Image 1: Portal effect using Perspective camera

Image 2: Portal effect using Oblique camera

Image 3: Oblique camera editor interface
